/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.brands.application.ics.facade;

import br.com.brands.application.ics.beans.ProductsBeans;
import br.com.brands.application.ics.delegate.ProductsDelegate;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

/**
 *
 * @author ppacheco
 */
@Stateless
public class ProductsFacadeBean implements ProductsFacadeBeanLocal {

    private static final Logger log = Logger.getLogger("br.com.brands.application.ics.facade.ProductsFacadeBean");

    public ProductsFacadeBean() {
        log.log(Level.INFO, "Loading Products - EJB Facade Layer Level");
    }

    @Override
    public ProductsBeans delete(ProductsBeans products) throws EJBException {

        ProductsBeans objRef = null;

        try {
            objRef = (ProductsBeans) ProductsDelegate.getInstance().delete(products);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public List<ProductsBeans> findAll(ProductsBeans products) throws EJBException {

        List<ProductsBeans> list = null;

        try {
            list = (List<ProductsBeans>) ProductsDelegate.getInstance().findAll(products);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return list;
    }

    @Override
    public ProductsBeans findByID(ProductsBeans products, Long id, boolean lock) throws EJBException {

        ProductsBeans objRef = null;

        try {
            if (lock == true) {
                objRef = (ProductsBeans) ProductsDelegate.getInstance().findByID(products, id, lock);
            }
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public ProductsBeans save(ProductsBeans products) throws EJBException {

        ProductsBeans objRef = null;

        try {
            objRef = (ProductsBeans) ProductsDelegate.getInstance().save(products);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public ProductsBeans saveOrUpdate(ProductsBeans products) throws EJBException {

        ProductsBeans objRef = null;

        try {
            objRef = (ProductsBeans) ProductsDelegate.getInstance().saveOrUpdate(products);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }
}
